package edu.gdkm.dao;

import edu.gdkm.pojo.Resume;
import org.apache.ibatis.annotations.*;
import java.util.List;

public interface ResumeDAO {
    
    // 根据ID查询简历
    @Select("SELECT * FROM resume WHERE id = #{id}")
    Resume findById(Long id);
    
    // 根据用户ID查询简历列表
    @Select("SELECT * FROM resume WHERE user_id = #{userId}")
    List<Resume> findByUserId(Long userId);
    
    // 根据简历名称查询简历
    @Select("SELECT * FROM resume WHERE resume_name = #{resumeName}")
    List<Resume> findByResumeName(String resumeName);
    
    // 查询所有简历
    @Select("SELECT * FROM resume")
    List<Resume> findAll();
    
    // 查询公开简历
    @Select("SELECT * FROM resume WHERE visibility = 1")
    List<Resume> findPublicResumes();
    
    // 插入简历
    @Insert("INSERT INTO resume(user_id, resume_name, template_id, education_experience, work_experience, " +
            "project_experience, skills, certificates, hobbies, language_ability, internship_experience, " +
            "visibility, create_time, update_time) " +
            "VALUES(#{userId}, #{resumeName}, #{templateId}, #{educationExperience}, #{workExperience}, " +
            "#{projectExperience}, #{skills}, #{certificates}, #{hobbies}, #{languageAbility}, " +
            "#{internshipExperience}, #{visibility}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Resume resume);
    
    // 更新简历
    @Update("UPDATE resume SET user_id=#{userId}, resume_name=#{resumeName}, template_id=#{templateId}, " +
            "education_experience=#{educationExperience}, work_experience=#{workExperience}, " +
            "project_experience=#{projectExperience}, skills=#{skills}, certificates=#{certificates}, " +
            "hobbies=#{hobbies}, language_ability=#{languageAbility}, internship_experience=#{internshipExperience}, " +
            "visibility=#{visibility}, update_time=#{updateTime} WHERE id=#{id}")
    int update(Resume resume);
    
    // 根据ID删除简历
    @Delete("DELETE FROM resume WHERE id = #{id}")
    int deleteById(Long id);
    
    // 根据用户ID删除简历
    @Delete("DELETE FROM resume WHERE user_id = #{userId}")
    int deleteByUserId(Long userId);
}
